package com.yh.autobio.fragment;

import android.support.v4.app.Fragment;

import com.yh.autobio.R;
import com.yh.autobio.base.BaseViewPagerFragment;
import com.yh.autobio.interf.OnTabReselectListener;
import com.yh.autobio.modules.adatper.ViewPageFragmentAdapter;

/**
 * =========================
 * 版权所有，违法必究
 * 作者：john
 * <p>
 * 工程：FoodBarcode
 * <p>
 * 文件名：MatOrGiftJPageFragment
 * <p>
 * 创建时间：2017.05.25.15:44
 * *****************************
 */
public class MatOrGiftJPageFragment extends BaseViewPagerFragment implements
        OnTabReselectListener {
    @Override
    protected void onSetupTabAdapter(ViewPageFragmentAdapter adapter) {
        String[] title = getResources().getStringArray(
                R.array.matorgift_viewpage_arrays);
        adapter.addTab(title[0], "sp", ComListFragment.class,
                getArguments());
        adapter.addTab(title[1], "zp", GiftListFragment.class,
                getArguments());
    }

    @Override
    protected void setScreenPageLimit() {
        mViewPager.setOffscreenPageLimit(2);
    }


    @Override
    public void onTabReselect() {
        try {
            int currentIndex = mViewPager.getCurrentItem();
            Fragment currentFragment = getChildFragmentManager().getFragments()
                    .get(currentIndex);
            if (currentFragment != null
                    && currentFragment instanceof OnTabReselectListener) {
                OnTabReselectListener listener = (OnTabReselectListener) currentFragment;
                listener.onTabReselect();
            }
        } catch (NullPointerException e) {
        }
    }
}
